package com.stu.student_back_end.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stu.student_back_end.controller.dto.CountDTO;
import com.stu.student_back_end.controller.dto.PageDTO;
import com.stu.student_back_end.entity.TblNoHere;
import com.stu.student_back_end.mapper.TblNoHereMapper;
import com.stu.student_back_end.service.ITblNoHereService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * moveAndOut Service层实现类
 */
@Service
public class TblNoHereServiceImpl extends ServiceImpl<TblNoHereMapper, TblNoHere> implements ITblNoHereService {

    /**
     * 分页查询
     * @param pageDTO
     * @return
     */
    @Override
    public Page<TblNoHere> queryNoHerePage(PageDTO pageDTO) {
        Page<TblNoHere> page =new Page<>(pageDTO.getCurrentPage(),pageDTO.getSizePage());
        Page<TblNoHere> noHerePage = new Page<>();
        //判断是否带关键字
        if(!(pageDTO.getKeyWord() == "")) {
            //不为空
            noHerePage = page(page, new LambdaQueryWrapper<TblNoHere>().like(TblNoHere::getStudentName, pageDTO.getKeyWord()));
        }else {
            noHerePage = page(page);
        }
        return noHerePage;
    }

    /**
     * 插入记录
     * @param noHere
     * @return
     */
    @Override
    public int saveNoHere(TblNoHere noHere) {
        int insert = baseMapper.insert(noHere);

        return insert;
    }

    @Override
    public CountDTO queryNoHereCount() {
        CountDTO countDTO = new CountDTO();
        countDTO.setCount(baseMapper.queryNoHereCount());
        countDTO.setName("缺寝记录");
        return countDTO;
    }

    @Override
    public Page<TblNoHere> queryByNameNoHere(PageDTO pageDTO, String name) {
        Page<TblNoHere> page =new Page<>(pageDTO.getCurrentPage(),pageDTO.getSizePage());
        Page<TblNoHere> noHerePage = new Page<>();
        //判断是否带关键字
        if(!(pageDTO.getKeyWord() == "")) {
            //不为空
            noHerePage = page(page, new LambdaQueryWrapper<TblNoHere>().like(TblNoHere::getStudentName, name));
        }else {
            noHerePage = page(page);
        }
        return noHerePage;
    }

}
